<%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2022/11/17
  Time: 19:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>出库审核模态框</title>
</head>
<body>
        <form id="outboundregistrationexaminemodalform">
        <div class="modal-header">
            <input type="submit"  class="btn btn-default" value="审核">
            <button class="close" data-dismiss="modal">退出</button>
            <input type="hidden" name="id" id="outboundregistraptionmodalidon">
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-md-offset-5"><h2><strong>出库单</strong></h2></div>
            </div>
            <br>
            <div class="row">
                <div class="col-md-6">
                    <table>
                        <tr>
                            <td>出库单编号:</td>
                            <td><input type="text" name="payId" id="outboundregistrationmodalpayIdon" readonly style="outline: none;border: none;"></td>
                        </tr>
                        <tr>
                            <td>出库理由:</td>
                            <td><input type="text"  id="outboundregistrationmodalreasonon" readonly style="outline: none;border: none;"></td>
                        </tr>
                    </table>
                </div>
                <div class="col-md-6">
                    <table>
                        <tr>
                            <td>出库理由详情：</td>
                            <td><input id="outboundregistrationmodalreasonexacton" type="text" readonly style="outline: none;border: none"></td>
                        </tr>
                    </table>
                </div>
                <br>
                <div style="height:45%;">
                    <table id="outboundregistrationmodaltabon"></table>
                </div>
                <br>
                <div class="row">
                    <div class="col-md-6">
                        <table>
                            <tr>
                                <td>应出库数量:</td>
                                <td><input type="text" name="amountSum" id="outboundregistrationmodalamountSumon" readonly style="outline: none;border: none"></td>
                            </tr>
                            <tr>
                                <td>应出库总成本:</td>
                                <td><input type="text" id="outboundregistrationmodalcostPriceSumon" readonly style="outline: none;border: none"></td>
                            </tr>
                            <tr>
                                <td>登记人:</td>
                                <td><input type="text" readonly name="register" id="outboundregistrationmodalregisteron" required style="outline: none;border: none;border-bottom: 1px black dashed"></td>
                            </tr>
                            <tr>
                                <td>登记复核人:</td>
                                <td><input type="text" name="registrationreviewer" id="outboundregistrationmodalchecker" value="${username}" required style="outline: none;border: none;border-bottom: 1px black dashed"></td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <table>
                            <tr>
                                <td>已出库数量:</td>
                                <td><input type="text" name="paidAmountSum"  id="outboundregistrationmodalpaidAmountSumon" readonly style="outline: none;border: none"></td>
                            </tr>
                            <tr>
                                <td>已出库总成本:</td>
                                <td><input type="text" id="outboundregistrationmodalcostPriceSumson" readonly style="outline: none;border: none"></td>
                            </tr>
                            <tr>
                                <td>登记时间:</td>
                                <td><input type="text" name="registerTime" id="outboundregistrationmodalregisterTimeon" readonly style="outline: none;border: none;"></td>
                            </tr>
                            <tr>
                                <td>登记复核时间:</td>
                                <td><input type="text" name="timeregistrationreviewer" id="outboundregistrationmodalcheckTime" readonly style="outline: none;border: none;"></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        </form>

        <script>
            //加载表格数据
            $(function () {
                $("#outboundregistrationmodaltabon").bootstrapTable({
                    sortable: true,//是否显示排序
                    sortOrder: "aso",//排序方式
                    sidePagination:"server", //分页方式：client客户端分页，server服务端分页（*）
                    showColumns: true,//是否显示所有的列（选择显示的列）
                    showRefresh: true,//是否显示刷新按钮
                    minimumCountColumns: 2,//最少允许的列数
                    showToggle: true,//是否显示详细视图和列表视图的切换按钮
                    cardView: false,//是否显示详细视图
                    detailView: false,//是否显示父子表,
                    queryParams:function (params) {
                        var outboundregistrationmodal={
                            pagesize:params.limit,
                            pageno:(params.offset/params.limit)+1,
                            sort:params.sort,
                            sortOrder:params.sort,
                        }
                        return outboundregistrationmodal
                    },
                    columns:[
                        {
                            field:"",
                            title:"序号",
                            formatter:function (value,row,index) {
                                return Number(index)+1
                            }
                        },
                        {
                            field:"productId",
                            title:"产品编号",
                        },
                        {
                            field:"productName",
                            title:"产品名称",
                        },
                        {
                            field:"costPrice",
                            title:"成本价格",
                        },
                        {
                            field:"cell",
                            title:"当前库存",
                            formatter:function (value,row,index) {
                                return value.amount
                            }
                        },
                        {
                            field:"amount",
                            title:"应出库数量",
                        },
                        {
                            field:"warehousing",
                            title:"已出库数量",
                        },
                        /* {
                             field:"paidAmount",
                             title:"出库数量",
                         },*/
                        {
                            field:"paidAmount",
                            title:"本次出库数量",
                        },

                    ]
                })
                //获取值
                var payId='${param.payId}'
                $.post("queryByPayCellPayDetails.action",{"payId":payId},function (data) {
                    console.log(data)
                    //出库编号
                    $("#outboundregistrationmodalpayIdon").val(data.payId)
                    //出库理由
                    var reasons="";
                    if(data.reason=="C002-1"){
                        reasons="生产领料"
                    }
                    if(data.reason=="C002-2"){
                        reasons="赠送"
                    }
                    if(data.reason=="C002-3"){
                        reasons="内部借领"
                    }
                    if(data.reason==" C002-4"){
                        reasons="其他借领"
                    }
                    $("#outboundregistrationmodalreasonon").val(reasons)
                    //出库详情理由
                    $("#outboundregistrationmodalreasonexacton").val(data.reasonexact)
                    //应出库数量
                    $("#outboundregistrationmodalamountSumon").val(data.amountSum)
                    //应出库总成本
                    $("#outboundregistrationmodalcostPriceSumon").val(data.costPriceSum)
                    //登记人
                    $("#outboundregistrationmodalregisteron").val(data.register)
                    $("#outboundregistraptionmodalidon").val(data.id)
                    //登记时间
                    $("#outboundregistrationmodalregisterTimeon").val(data.registerTime)
                    //点击获取当前时间
                    $.get("queryCellByDate.action",function (datas) {
                        $("#outboundregistrationmodalcheckTime").val(datas.datetime)
                    },"json")
                    //加载表格数据集
                    var arr=[]
                    var arrs=data.payDetails;
                    for(var i=0;i<arrs.length;i++){
                        arr.push(arrs[i])
                    }
                    //加载给表格
                    $("#outboundregistrationmodaltabon").bootstrapTable("append",arr)
                    //获取值
                    var paydetalis=$("#outboundregistrationmodaltabon").bootstrapTable("getData")
                    var i=0;
                    console.log(data.payDetails)
                    var nums=0;
                    $(paydetalis).each(function (index,item) {
                        i+=Number(item.warehousing);
                        nums+=i*data.payDetails[index].costPrice;
                    })
                    //已出库数量
                    $("#outboundregistrationmodalpaidAmountSumon").val(i)
                    //已出库总成本
                    $("#outboundregistrationmodalcostPriceSumson").val(nums)
                },"json")
            })
            //审核
            $("#outboundregistrationexaminemodalform").validate({
                    submitHandler:function () {
                        //获取form的值
                        var arr=$("#outboundregistrationexaminemodalform").serializeArray();
                        var pay={}
                        $(arr).each(function (index,item) {
                            pay[item.name]=item.value;
                        })
                        //获取表格数据
                       var paydetails=$("#outboundregistrationmodaltabon").bootstrapTable("getData")
                        pay["payDetails"]=paydetails
                        console.log(pay)
                      $.ajax({
                          url:"updatePayPayDetailsCellstatus.action",
                          data:JSON.stringify(pay),
                          contentType:"application/json",
                          type:"post",
                          dataType:"json",
                          success:function (data) {
                                alert(data.msg)
                                //关闭模态框  刷新表格
                                $("#outboundregistrationexaminemodal").modal("hide")
                                $("#outboundregistrationexaminetab").bootstrapTable("refresh")
                          }
                      })
                    }
            })
        </script>

</body>
</html>
